import {gameFlowSessionStore} from "@/renderer/share/stores/sotreCurrentGameSession.js";
import {storeSystemCertificateInfo} from "@/renderer/main-window/stores/storeSystemCertificateInfo.js";

const updateEvent = 'Update';
const deleteEvent = 'Delete';

export function initGameSession() {
    window.electron.ipcRenderer.on('sync/phase', (event, {data, eventType}) => {
        if (data) {
            gameFlowSessionStore().setGamePhase(data);
        }
    })

    window.electron.ipcRenderer.on('sync/champion-session', (event, {data, eventType}) => {
        console.log(`接收到英雄选择会话 ${eventType}`)
        if (eventType === updateEvent) {
            gameFlowSessionStore().setChampSelectSession(data);
        } else if (eventType === deleteEvent) {
            gameFlowSessionStore().setChampSelectSession({});
        }
    })

    window.electron.ipcRenderer.on('sync/lobby', (event, {data, eventType}) => {
        if (eventType === updateEvent) {
            gameFlowSessionStore().setLobby(data);
        } else if (eventType === deleteEvent) {
            gameFlowSessionStore().setLobby({});
        }
    })


    window.electron.ipcRenderer.on('sync/game-flow', (event, {data, eventType}) => {
        if (eventType === updateEvent) {
            gameFlowSessionStore().setGameFlow(data);
        } else if (eventType === deleteEvent) {
            gameFlowSessionStore().setGameFlow({});
        }
    })


    //lcu服务状态，接收推送的状态信息
    window.electron.ipcRenderer.on('lcu-server/status/push', (event, {connectStatus}) => {
        storeSystemCertificateInfo().setLcuServerStatus(connectStatus)
    })

}